<template>
	<view class="invite">
		<topTitle :title="$t('invite.title')" />

		<view class="inviteInfo">
			<view class="com">
				<view class="guide">
					<view>
						<view>
							<image src="@/static/image/74.png" mode="widthFix" />
						</view>
						<view>{{ $t('invite.guide.sendInvitation') }}</view>
					</view>

					<view>
						<view>
							<image src="@/static/image/75.png" mode="widthFix" />
						</view>
						<view>{{ $t('invite.guide.friendRegister') }}</view>
					</view>

					<view>
						<view>
							<image src="@/static/image/76.png" mode="widthFix" />
						</view>
						<view>{{ $t('invite.guide.getRebate') }}</view>
					</view>
				</view>
			</view>
			<view class="look">
				<image src="@/static/image/82.png" mode="widthFix" />
				<view><text @click="goTo('/pages/index/invitationRewards')">{{ $t('invite.lookRewards') }}</text>
				</view>
			</view>

			<view class="rechargeAddress">
				<view class="ipt">
					<view>{{ $t('invite.rechargeAddress.myInviteCode') }}</view>
					<view>
						{{ UserInfoObj.id_no }}
						<image @click="copyText(UserInfoObj.id_no)" class="icon" src="@/static/image/80.png"
							mode="widthFix" />
					</view>
				</view>
				<view class="ipt">
					<view>{{ $t('invite.rechargeAddress.inviteLink') }}</view>
					<view>
						{{ interceptFn(shareUrl, 20) }}
						<image @click="copyText(shareUrl)" class="icon" src="@/static/image/80.png" mode="widthFix" />
					</view>
				</view>
				<view class="codeBg">
					<up-qrcode :size="150" :val="shareUrl"></up-qrcode>
				</view>
				<view class="tips">{{ $t('invite.rechargeAddress.scanQRCode') }}</view>
				<view class="btn" @click="show = true">{{ $t('invite.rechargeAddress.share') }}</view>
			</view>
		</view>
		<up-popup :show="show" :round="25" mode="bottom" @close="show = false" @open="show = true" closeable>
			<view class="shareList" @touchmove.stop>
				<view>{{ $t('invite.sharePopup.inviteFriend') }}</view>
				<view class="imgList">
					<view @click="copyText('1')">
						<view>
							<image :src="'../../static/image/shareIcon/copy.png'" mode="widthFix" />
						</view>
						<view>{{ $t('invite.sharePopup.copyLink') }}</view>
					</view>
					<view v-for="(item, idx) in shareArr" :key="idx" @click="shareFn(item)">
						<view>
							<image :src="'../../static/image/shareIcon/' + idx + '.png'" mode="widthFix" />
						</view>
						<view>{{ item.name }}</view>
					</view>
				</view>
			</view>
		</up-popup>
	</view>
</template>


<script setup lang="ts">
	import { ref, getCurrentInstance } from "vue";
	const instance = getCurrentInstance()?.appContext.config.globalProperties;
	import configs from "@/static/ts/config";

	let shareUrl = ref<any>()
	const show = ref<boolean>(false);
	let shareArr = ref<Array<any>>()
	shareArr.value = [
		{
			name: 'tumblr',
			url: 'tumblr://www.tumblr.com/'
		},
		{
			name: 'pinterest',
			url: 'pinterest://www.pinterest.com/'
		},
		{
			name: 'linkedin',
			url: 'linkedin://www.linkedin.com/'
		},
		{
			name: 'telegramm',
			url: 'tg://resolve?domain='
		}, // 适用于Telegram
		{
			name: 'skype',
			url: 'skype:'
		},
		{
			name: 'YouTube',
			url: 'vnd.youtube://'
		}, // 用于打开YouTube
		{
			name: 'watsapp',
			url: 'whatsapp://send'
		},
		{
			name: 'Facebook',
			url: 'fb://profile/'
		}, // 用于打开Facebook
		{
			name: 'twitter',
			url: 'twitter://user?screen_name='
		}, // 用于打开Twitter
		{
			name: 'vk',
			url: 'vk://profile'
		}, // 用于打开VK
		{
			name: 'Line',
			url: 'line://ti/p/'
		}, // 用于打开Line
		{
			name: 'tiktok',
			url: 'musical.ly://'
		}, // 用于打开TikTok
		{
			name: 'snackvideo',
			url: 'snackvideo://'
		}, // 用于打开SnackVideo
		{
			name: 'Discord',
			url: 'discord:///'
		},
		{
			name: 'instagram',
			url: 'instagram://user?username='
		}, // 用于打开Instagram
		{
			name: 'Bumble',
			url: 'bumble://'
		}, // 用于打开Bumble
		{
			name: 'Badoo',
			url: 'badoo://'
		}, // 用于打开Badoo
		{
			name: 'Litmatch',
			url: 'litmatch:///'
		}, // 用于打开Litmatch
		{
			name: 'boo',
			url: 'boo://'
		}, // 用于打开Boo
		// {
		// 	name: 'Tinder',
		// 	url: 'tinder://app'
		// }, // 用于打开Tinder
		// {
		// 	name: 'michat',
		// 	url: 'michat:///'
		// }, // 用于打开MiChat
		// {
		// 	name: 'meetme',
		// 	url: 'meetme:///'
		// }, // 用于打开MeetMe
		// {
		// 	name: 'Lamour',
		// 	url: 'lamour:///'
		// } // 用于打开Lamour
	]
	let UserInfoObj = ref<any>({})
	UserInfoObj.value = uni.getStorageSync("userInfo");

	/*#ifdef H5*/
	shareUrl.value = window.location.origin + '/#/pages/notLoggedIn/reg?id_no=' + UserInfoObj.value.id_no
	/*#endif*/
	/*#ifdef APP-PLUS*/
	shareUrl.value = configs.baseUrl + '/#/pages/notLoggedIn/reg?id_no=' + UserInfoObj.value.id_no
	/*#endif*/

	const shareFn = (item : any) => {
		instance?.copyText(item)
		instance?.handleDownload(item.url)
	}

	const loginFn = () => {
		if (!uni.getStorageSync('userInfo')) {
			instance?.goRedirectTo('/pages/notLoggedIn/index')
		}
	}
	loginFn()
</script>
<style scoped lang="scss">
	@import "../../static/scss/invite.scss";
</style>